package com.stqf.scala.grammar.collection

import scala.collection.mutable
import scala.collection.immutable

/**
  * Created by ASUS on 2018-02-01.
  */
object MapLearn {
  def main(args: Array[String]): Unit = {
    val mutableMaps = mutable.Map[String, Int]()
    mutableMaps.put("Stqf", 5)
    mutableMaps.foreach(temp => println(temp._1 + "\t" + temp._2))
    var immutableMap = Map[String, String](("Hello", "World"))
    immutableMap = immutableMap.++(Map[String, String]("good" -> "study"))
    immutableMap.foreach(temp => println(temp._1 + "\t" + temp._2))
    immutableMap.iterator.foreach(println)
    println(immutableMap)
    //println(immutableMap.apply("god"))
    println(immutableMap.contains("goot"))

    //不可变Map练习
    var maps: Map[String, Int] = Map()
    println("maps初始化:" + maps)
    maps = maps.+(("salary", 30))
    println("maps单个元素添加:" + maps)
    maps = maps.+(("salary", 30))
    maps = maps.+(("salary", 30))
    maps = maps.+(("age", 60), ("time", 20180202))
    println("maps多个元素添加:" + maps)
    maps.keySet.foreach(m => println(m + "\t" + maps(m)))
  }
}
